#!/usr/bin/env python
# -*- coding: utf-8 -*-

# dialogs/default.py

# Copyright 2009-2010 Diego Hansen Hahn (aka DiegoHH) <diegohh90 [at] hotmail [dot] com>

# lazynds is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.

# lazynds is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with lazynds. If not, see <http://www.gnu.org/licenses/>.

import gtk

license = '''lazynds is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.

lazynds is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with lazynds. If not, see <http://www.gnu.org/licenses/>.'''

def FileChooser(window, folder, extensions, mode):
    if mode == 'save':
        title = 'Salvar arquivo...'
        action = gtk.FILE_CHOOSER_ACTION_SAVE
        buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)
    else:
        title = 'Abrir Arquivo...'
        action = gtk.FILE_CHOOSER_ACTION_OPEN
        buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)

    chooser = gtk.FileChooserDialog(title = title,
                                    parent = window,
                                    action = action,
                                    buttons = buttons)

    chooser.set_position(gtk.WIN_POS_CENTER_ALWAYS)
    chooser.set_do_overwrite_confirmation(True)

    if extensions:
        for filter in extensions:
            chooser.add_filter(filter[1])

    chooser.set_current_folder(folder)

    filename = None

    response = chooser.run()
    if response == gtk.RESPONSE_OK:
        filename = chooser.get_filename()
    filter = chooser.get_filter()
    folder = chooser.get_current_folder()
    chooser.destroy()

    return (filename, folder, filter)

def Error(window, error_string):
    error_dlg = gtk.MessageDialog(parent = window,
                                  flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                                  type=gtk.MESSAGE_ERROR,
                                  message_format=error_string,
                                  buttons=gtk.BUTTONS_OK)

    error_dlg.set_title("Erro!")
    error_dlg.run()
    error_dlg.destroy()

def Warning(window, buttons, warning_string):
    warning_dlg = gtk.MessageDialog(parent = window,
                                  flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                                  type=gtk.MESSAGE_WARNING,
                                  message_format=warning_string,
                                  buttons=buttons)

    warning_dlg.set_title('Aviso!')
    if warning_dlg.run() == gtk.RESPONSE_NO: ret = False
    else: ret = True

    warning_dlg.destroy()
    return ret

def About(window):
    def close(dialog, response):
        dialog.destroy()

    def delete_event(dialog, event):
        return True

    about_dialog = gtk.AboutDialog()
    about_dialog.set_transient_for(window)
    about_dialog.set_destroy_with_parent(True)
    about_dialog.set_name("lazynds")
    about_dialog.set_version("2.0.3")
    about_dialog.set_license(license)
    about_dialog.set_copyright("Copyright \xc2\xa9 2008-2010 Monkeys Traduções")
    about_dialog.set_website("http://lazynds.googlecode.com")
    about_dialog.set_comments("Visualizador de Compressões")
    about_dialog.set_authors(["Diego Hansen Hahn <diegohh90@hotmail.com>"])
    about_dialog.set_logo(gtk.gdk.pixbuf_new_from_file('pixmaps/logo.png').add_alpha(True, chr(255), chr(255), chr(255)))

    about_dialog.connect("response", close)
    about_dialog.connect("delete-event", delete_event)

    return about_dialog